home *** CD-ROM | disk | FTP | other *** search
- /* $Id: 3DBSTYPE.H 1.43 1997/05/07 06:02:35 damien Exp $ */
- /*****************************************************************************\
- * *
- * 3DBsType.h - Basic 3D types definition *
- * *
- * Common to EVX and COM interfacing. *
- * Uses QuickMath unless qUsesQuickMath is false. *
- * *
- * Copyright (c) 1995, Ray Dream, Inc. All rights reserved. *
- * *
- \*****************************************************************************/
-
- #ifndef __3DBSTYPE__
- #define __3DBSTYPE__
-
- // QuickMath. We use QMath.h by default
- // If you do not want to use QuickMath, define qUsesQuickMath and define the NUM3D;
- // VECTOR2D, and VECTOR3D types before including this file.
- #ifndef qUsesQuickMath
- #define qUsesQuickMath 1
- #endif
-
- #if qUsesQuickMath
- #include "QMath.h"
- typedef QuickFix NUM3D;
- typedef QuickFixVector2 VECTOR2D;
- typedef QuickFixVector3 VECTOR3D;
- #else
- // type definitions for the toolkit SDK
- #ifdef _WIN
- #pragma warning(disable: 4244) // conversion from 'type1' to 'type2', possible loss of data
- #endif
-
- typedef float NUM3D;
- struct VECTOR2D {
- NUM3D& operator[](int i) {return fData[i];}
- const NUM3D& operator[](int i) const {return fData[i];}
- NUM3D fData[2];
- };
- struct VECTOR3D {
- NUM3D& operator[](int i) {return fData[i];}
- const NUM3D& operator[](int i) const {return fData[i];}
- NUM3D fData[3];
- };
-
- #define SQR(X) ((X)*(X))
-
- #ifndef __MTYPES__
- #include "mtypes.h"
- #endif
-
- #endif //qUsesQuickMath
-
- #ifdef _MAC
- #ifdef qPowerPC
- typedef double Double;
- #else
- typedef long double Double;
- #endif
- #endif
-
- #ifdef _WIN
- typedef double Double;
- #endif
-
- struct I3DShInstance;
- struct IShRasterOffscreen;
-
- /** Constants **************************************************/
-
- //-- Shading Level
- enum ShadingLevel {
- kShLvlNoChanges=-1, // No Changes - Use renderer’s default shading level
- kShLvlInvisible=0, // Invisible - Do not render
- kShLvlBBox=1, // Render bounding box only
- kShLvlWireFrame=2, // Wireframe
- kShLvlPreview=3, // Preview Shading - Fast and crude shading
- kShLvlFullShading=4 // Full Shading
- };
-
- enum {
- kDefaultMapping = -1,
- kParametricMapping=0,
- kBoxMapping=1,
- kCylindricalMapping=2,
- kSphericalMapping=3,
- kPassThruMapping=4
- };
-
- /** Base types defines **************************************************/
- typedef unsigned char BOOLEAN;
-
- #ifndef NULL
- #define NULL 0
- #endif
-
- #ifndef TRUE
- #define TRUE 1
- #endif
-
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- /** 3D types defines **************************************************/
-
- #ifndef BOX2D
- typedef struct BOX2D{
- VECTOR2D fMin;
- VECTOR2D fMax;
- } BOX2D;
- #define BOX2D BOX2D
- #endif
-
- #ifndef BOX3D
- typedef struct BOX3D {
- VECTOR3D fMin;
- VECTOR3D fMax;
- } BOX3D;
- #define BOX3D BOX3D
- #endif
-
- // The i, j and k vectors
- // can be considered as the unit vectors of the Local System,
- // and the fix, fiy,... values as they coordinates in the
- // Global Coordinates System.
- typedef struct MATRIX3D {
- NUM3D fix, fjx, fkx,
- fiy, fjy, fky,
- fiz, fjz, fkz;
- } MATRIX3D;
-
-
- // Matrix 3 x 3 + translation
- typedef struct TRANSFORM3D {
- MATRIX3D fR; // Rotation 3 x 3 matrix
- VECTOR3D fT; // Translation
- } TRANSFORM3D;
-
- // Tree transformation
- typedef struct TREETRANSFORM3D {
- MATRIX3D fR; // Rotation 3 x 3 matrix
- VECTOR3D fT; // Translation
- NUM3D fS; // Uniform scaling
- } TREETRANSFORM3D;
-
- #ifndef AFFINETRANSFORM
- struct AffineTransform {
- NUM3D fR[3][3];
- NUM3D fT[3];
- };
- #define AFFINETRANSFORM AffineTransform
- #endif
-
- #ifndef COLOR3D
- typedef struct COLOR3D {
- long Mode; // Color model. 0=RGB, 1=CMYK
- NUM3D R; // Red or Cyan
- NUM3D G; // Green or Magenta
- NUM3D B; // Blue or Yellow
- NUM3D A; // N/A or Black
- } COLOR3D;
- #define COLOR3D COLOR3D
- #endif
-
- typedef struct RGBCOLOR3D {
- unsigned short R;
- unsigned short G;
- unsigned short B;
- } RGBCOLOR3D;
-
- #ifndef RECT3D
- typedef struct RECT3D {
- short top;
- short left;
- short bottom;
- short right;
- } RECT3D;
- #define RECT3D RECT3D
- #endif
-
- #ifndef LRECT3D
- typedef struct LRECT3D {
- long top;
- long left;
- long bottom;
- long right;
- } LRECT3D;
- #define LRECT3D LRECT3D
- #endif
-
- #ifndef POINT3D
- typedef struct POINT3D {
- short h;
- short v;
- } POINT3D;
- #define POINT3D POINT3D
- #endif
-
- #ifndef LPOINT3D
- typedef struct LPOINT3D {
- long v; // Note the inverse order of v and h
- long h;
- } LPOINT3D;
- #define LPOINT3D LPOINT3D
- #endif
-
- typedef struct {
- long fId;
- long fPriority;
- long fMessage;
- long fWhen;
- short fLocalWhereH;
- short fLocalWhereV;
- short fGlobalWhereH;
- short fGlobalWhereV;
- short fPressure;
- BOOLEAN fLeftButton;
- BOOLEAN fRightButton;
- BOOLEAN fCommandKey;
- BOOLEAN fShiftKey;
- BOOLEAN fAlphaLock;
- BOOLEAN fOptionKey;
- BOOLEAN fControlKey;
- BOOLEAN fAutoKey;
- short fChar;
- short fKey;
- short fClickCount;
- long fActionNumber;
- void* fReserved;
- } PLATFORMEVENT;
-
- typedef struct VERTEX3D {
- VECTOR3D fVertex; // x, y, z vertex coordinates
- VECTOR3D fNormal; // Nx, Ny, Nz normal values at that vertex
- VECTOR2D fUV; // Texture u,v values at that vertex
- } VERTEX3D;
-
- typedef struct FACET3D{
- VERTEX3D fVertices[3]; // The facet three vertices
- short fUVSpace; // UV Space ID this facet belongs to
- short fReserved; // Reserved - 0
- } FACET3D;
-
- typedef struct PATCH3D{
- VECTOR3D fVertices[4][4]; // The patch 16 vertices
- NUM3D fu[2]; // u values at the patch boundaries
- NUM3D fv[2]; // v values at the patch boundaries
- short fUVSpace; // UV Space ID this patch belongs to
- short fReserved; // Reserved - 0
- } PATCH3D;
-
- struct FacetMesh {
- long fNbrFacets;
- long fNbrVertices;
- long fFacetStreamSize;
- void *fFacetStream;
- VERTEX3D *fVertices;
- };
-
- /** Shading defines **************************************************/
-
-
- enum {
- kColorChannel=1,
- kSpecularityChannel=2,
- kShininessChannel=4,
- kNormalChannel=8,
- kReflectionChannel=16,
- kTransparencyChannel=32,
- kRefractionChannel=64,
- kGlowChannel=128,
- kAllChannels = 1+2+4+8+16+32+64+128
- };
-
- typedef struct ShadingFlags{
- BOOLEAN fCallOnce; // Constant Shader: The shader needs to be called only once for the whole object or shading area
- BOOLEAN fNeedsColor; // Needs Color - Not used
- BOOLEAN fNeedsPoint; // Needs surface point in Global Coordinates
- BOOLEAN fNeedsNormal; // Needs surface Normal in Global Coordinates
- BOOLEAN fNeedsIsoU; // Needs U iso-parametric vector in Local Coordinates
- BOOLEAN fNeedsIsoV; // Needs V iso-parametric vector in Local Coordinates
- BOOLEAN fNeedsUV; // Needs u,v texture values
- BOOLEAN fNeedsPointLoc; // Needs surface point in Local Coordinates
- BOOLEAN fNeedsNormalLoc; // Needs surface Normal in Local Coordinates
- BOOLEAN fNeedsPixelRatio; // Needs Pixel Ratio - Not used yet - Future use
- BOOLEAN fChangesNormal; // The shader changes the Normal. The new Normal will have to be read in ShadingOut::fChangedNormal
- long fConstantChannelsMask;
- } ShadingFlags;
-
- typedef struct ShadingIn {
- COLOR3D fColor; // Color - Not used - For future use
- VECTOR3D fPoint; // Surface point in Global Coordinates
- VECTOR3D fNormal; // Surface Normal in Global Coordinates
- VECTOR3D fIsoU; // U iso-parametric vector in Local Coordinates
- VECTOR3D fIsoV; // V iso-parametric vector in Local Coordinates
- VECTOR2D fUV; // u,v texture values
- unsigned long fUVSpaceID; // UV Space ID
- VECTOR3D fPointLoc; // Surface point in Local Coordinates
- VECTOR3D fNormalLoc; // Surface Normal in Local Coordinates
- NUM3D fPixelRatio; // Pixel Ratio - Not used - For future use
- } ShadingIn;
-
- typedef struct ShadingOut{
- COLOR3D fColor; // Diffuse Color (Kd)
- COLOR3D fSpecularColor; // Specular Color (Ks)
- NUM3D fSpecularSize; // Specular highlight size (Ns)
- NUM3D fAmbient; // Ambient factor (Fa)
- NUM3D fLambert; // Diffuse factor (Fd)
- COLOR3D fReflection; // Reflectivity (Rx)
- COLOR3D fTransparency; // Transparency (Tx)
- NUM3D fRefractiveIndex; // Refraction index (Nr)
- COLOR3D fGlow; // Glow color
- VECTOR3D fChangedNormal; // Changed Normal in Global Coordinates
- } ShadingOut;
-
- typedef struct UVSpaceInfo {
- unsigned long fID; // UV Space ID
- VECTOR2D fMin; // UV Space minimum boundaries
- VECTOR2D fMax; // UV Space maximum boundaries
- BOOLEAN fWraparound[2]; // Tells is the UV Space is closed in the U or V direction
- } UVSpaceInfo;
-
- typedef struct ShadingInOut{
- ShadingIn* fIn; // Shading input parameters
- ShadingOut* fOut; // Shading output parameters
- UVSpaceInfo* fUVInfo; // UV Space information
- unsigned long fCurrentCompletionMask; // Internal flags for shaders. Must be set to 0x7F before calling DoShade
- } ShadingInOut;
-
-
- typedef struct FixPtRect { // Rectangle in a Shading Element.
- NUM3D fTop;
- NUM3D fLeft;
- NUM3D fBottom;
- NUM3D fRight;
- } FixPtRect;
-
- typedef struct FixPtRect ShadingElemRect;
-
- // Shading Element:
- // A Shading Element defines an area of Shading on an Object surface.
- // The area is defined in the surface UV Space.
- // fBBox and fShaderBox define the same rectangle in two different systems. fBBox is
- // in the UV Space, and thus defines the extent of the Shading Element on the Object
- // surface. fShaderBox defines the boundaries of the UV values that will be passed to
- // the Shader. Therefore, moving or rezising the Shading Element on the object surface
- // will not change the shading inside the Shading Element (provided that the Shader bases
- // its calculations on the UV values. Otherwise the discussion is pointless).
- typedef struct ShadingElem {
- ShadingElemRect fBBox; // Extent of the Shading Element in the UV Space
- ShadingElemRect fShaderBox; // Extent of the Shading Element as seen by the shader
- NUM3D fOpacity; // Opacity of the Shading Element vs. whatever other Shader Elements may be under
- } ShadingElem;
-
- /*****************************************************************************\
- * Lighting Model: *
- * *
- * -- -- *
- * \ \ Ns *
- * Color = Fa*Kd*Ia + / Fd*Kd*Ii(Li.N) + / Ks*Ii*(Ri.N) + Rx*(reflected color) + Tx*(transmitted color)
- * --i --i *
- * *
- * With: *
- * Ia: Ambient light color *
- * Ii: Color of the light source #i *
- * Li: Unit vector pointing from the surface point to light source #i *
- * N : Surface Normal *
- * Ri: Unit vector giving the reflection direction of the light source #i *
- * *
- * V1.V2 is a scalar product between 2 vectors: *
- * V1.V2 = V1.x*V2.x + V1.y*V2.y + V1.z*V2.z *
- * *
- * Refracted ray direction is computed using Snell's law: *
- * Nr1 * Sinus(alpha1) = Nr2 * Sinus(alpha2) *
- * *
- * *
- \*****************************************************************************/
-
-
- /** Ray-tracing defines **************************************************/
-
- typedef struct Ray3D {
- VECTOR3D fOrigin; // Origin of the ray
- VECTOR3D fDirection; // Direction of the ray
- NUM3D fFocalPoint; // ???
- NUM3D fAngle; // ???
- NUM3D fWidthAtFocal; // ???
- } Ray3D;
-
- class RDList;
-
- typedef struct RayHit3D{
- VECTOR3D fPosition; // Intersection point in Local Coordinates
- VECTOR3D fNormal; // Normal at that point in Local Coordinates
- VECTOR2D fUV; // (u,v) texture values at that point
- NUM3D ft; // t parameter along the ray: fPosition = RayOrigin + t * RayDirection
- VECTOR3D fIsoU; // Isoparametric U vector in the Object Local Coordinates
- VECTOR3D fIsoV; // Isoparametric V vector in the Object Local Coordinates
- I3DShInstance *fInstance; // instance that was hit
- BOOLEAN fShouldSetUV; // TRUE if fUV should be set
- BOOLEAN fShouldSetIsoUV; // TRUE if fIsoU and fIsoV should be set
- FACET3D fFacet; //facet hit
- NUM3D fBaryCoord[3]; //barycentric coordinates of hit point on hot facet
- void (*fCalcInfo)(RayHit3D &me);
- AFFINETRANSFORM fT;
- AFFINETRANSFORM fInvT;
- } RayHit3D;
-
- typedef BOOLEAN (*FilterHitProc) (I3DShInstance* instance);
-
- typedef struct RayHitParameters {
- NUM3D tmin;
- NUM3D tmax;
- BOOLEAN fShouldSetS;
- BOOLEAN fShouldSetUV;
- BOOLEAN fZBShading;
- BOOLEAN fNoGrid;
- void *fFilterInstance;
- BOOLEAN fRenderInfinitePrimitives;
- } RayHitParameters;
-
- typedef void (*RayHitCallback)(Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, void* privData);
- //typedef void (*RayTraceCallback)(HitInfo* hitInfo, void* privData);
-
-
- //*********************************************************************************
-
- class SDGraphicDevice;
- struct I3DShInstance;
- typedef void (*EnumPatchesCallback) (PATCH3D* patch, void* privData);
- typedef void (*EnumFacetsCallback) (FACET3D* facet, void* privData);
-
- typedef struct GBufferData {
- void* data;
- long channelBits;
- long channelOffsetBits;
- long columnBits;
- long rowBits;
- short nbrChannels;
- } GBufferData;
-
- typedef struct GBuffer {
- GBufferData color;
- GBufferData distance;
- GBufferData position;
- GBufferData normal;
- GBufferData alpha;
- GBufferData index;
- GBufferData surface;
- } GBuffer;
-
- typedef struct LightTraceElement {
- VECTOR3D fPoint1;
- VECTOR3D fVector1;
- VECTOR3D fPoint2;
- VECTOR3D fVector2;
- } LightTraceElement;
-
-
- //****** Parameter blocks for building extrusions ******************************
-
- #ifdef __cplusplus
- struct I3DShCrossSection;
- #else
- typedef void* I3DShCrossSection;
- #endif
-
-
- typedef struct Path3DPoint {
- VECTOR3D fVertex; // Vertex
- // Fill these only if using envelopes:
- VECTOR3D fTopEnv; // Envelope: top curve on right wall
- VECTOR3D fBotEnv; // Envelope: bottom curve on right wall
- VECTOR3D fLeftEnv; // Envelope: left curve on floor
- VECTOR3D fRightEnv; // Envelope: right curve on floor
- } Path3DPoint;
-
- typedef struct ExtrusionHeaderPB {
- Path3DPoint f3DPathPrevControl1; // Don't fill this if 1st section
- Path3DPoint f3DPathPrevControl2; // Don't fill this if 1st section
- VECTOR3D f3DPathVertex; // Put 0 in x and z unless you know what you're doing
- BOOLEAN fFill;
- BOOLEAN fSkinToNext;
- } ExtrusionHeaderPB;
-
- typedef struct ExtrusionPB { // Adding a non-automatic cross-section
- ExtrusionHeaderPB fHeader;
- //-- Specific parameters:
- I3DShCrossSection* fCrossSection;
- NUM3D fTwisting; // Twisting angle
- } ExtrusionPB;
-
- typedef struct ExtrusionAutoPB { // Adding an automatic cross-section
- ExtrusionHeaderPB fHeader;
- //-- Specific parameters:
- NUM3D fTopScaling;
- NUM3D fBotScaling;
- NUM3D fLeftScaling;
- NUM3D fRightScaling;
- } ExtrusionAutoPB;
-
- // Envelope flags:
- enum { kExtrFree=0, // Free Envelope
- kExtrSym=1, // Symetrical Envelope
- kExtrSemiSym=6}; // Semi-symetrical Envelope
-
- //*********************************************************************************
-
- #ifdef __cplusplus
- struct I3DShTreeElement;
- #else
- typedef void* I3DShTreeElement;
- #endif
-
- typedef struct CollisionInfo {
- I3DShTreeElement *fObject1;
- I3DShTreeElement *fObject2;
- VECTOR3D fHitPosition;
- VECTOR3D fNormal1;
- VECTOR3D fNormal2;
- VECTOR3D fVelocity1;
- VECTOR3D fVelocity2;
- } CollisionInfo;
-
- #endif
-
-